exports.__esModule = true;

function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }

exports.default = class extends think.Service {
    constructor() {
        super();
        this.areaModel = this.db['sys_area'];
    }

    /**
     * 树形结构化返回区域数据
     * @returns {Promise<*>}
     */
    getAreaList() {
        var _this = this;

        return _asyncToGenerator(function* () {
            const Op = _this.db.sequelize.Op;

            const areaList = yield _this.areaModel.findAll({
                where: {
                    parent_ids: {
                        [Op.like]: '%0,1,2580,%' //云南省
                    }
                }, raw: true
            });
            if (areaList.length > 0) {
                return new _this.TreeService().transData(areaList);
            }
            return null;
        })();
    }

    /**
     * 获取区域数据
     */
    getAllArea() {
        var _this2 = this;

        return _asyncToGenerator(function* () {
            const Op = _this2.db.sequelize.Op;
            const where = {
                parent_ids: {
                    [Op.like]: '%0,1,2580,%' //云南省
                }
            };
            return _this2.areaModel.findAll({ where: where, raw: true });
        })();
    }

    /**
     * 根据area_code查询区域
     */
    queryAreaByAreaCode(area_code) {
        var _this3 = this;

        return _asyncToGenerator(function* () {
            const where = { area_code: area_code };
            try {
                let result = yield _this3.areaModel.findAll({ where: where });
                return result;
            } catch (error) {
                return _this3.exceptionService.handleError(error);
            }
        })();
    }

    /**
     * 根据id
     * 查询区域
     */
    queryAreaById(id) {
        var _this4 = this;

        return _asyncToGenerator(function* () {
            const where = { id: id };
            try {
                let result = yield _this4.areaModel.findAll({ where: where });
                return result;
            } catch (error) {
                return _this4.exceptionService.handleError(error);
            }
        })();
    }
};